search.parse();

var grid = search.get('datagrid');
// 加载功能按钮
var isrecycle = __param.recycle ? true : false;
var gridutil = new DatagridUtil(grid, {
	funcid : __param.funcid,
	isRecycle : isrecycle,
	updateEntitystateUrl : __ctx + '/users/updateEntitystate.xhtml',
	updateEntitystateMethodName : {
		frozen : {
			oper : 'frozen', 
			msg : '确定要冻结吗？'
		},
		thaw : {
			oper : 'thaw', 
			msg : '确定要解冻吗？'
		}
	},
	validateRules : [
		{methodname : 'edit', conditions : [[1], [3]], ismultiple : false},
		{methodname : 'del', conditions : [[1], [3]], ismultiple : true},
		{methodname : 'frozen', conditions : [[1]], ismultiple : true},
		{methodname : 'thaw', conditions : [[3]], ismultiple : true},
		{methodname : 'resetpwd', conditions : [[1], [3]], ismultiple : true},
		{methodname : 'recycleRestore', conditions : [[2]], ismultiple : true},
		{methodname : 'recycleDelete', conditions : [[2]], ismultiple : true}
	],
	validateOptions : {
		fields : ['entitystate'],
		ignoretypes : ['add', 'queryDetail']
	}
});

// 页面加载完成执行
$(function() {
	grid.url = __ctx + '/users/findPageByParamsMap.xhtml';
	grid.load({isrecycle : isrecycle});
})

// 绘制表格单元格
function ondrawcell(e) {
	var field = e.column.field, record = e.record, fieldval = record[field];
	// 状态
	if (field == 'entitystate') {
		e.html = (fieldval == 1 ? '正常' : '冻结');
	} else if (field == 'initpassword') {
		e.html = (fieldval) ? '是' : '否';
	}
}

// 新增
function add(e) {
	var data = {
		url : __ctx + "/users/goUsersEditPage.xhtml",
		title : "新增",
		width : 450,
		height : 450,
		onload : function(window) {
			window.loadData({action : 'add'});
		},
		ondestroy : function(result){
			if (result == 'ok')
				grid.reload();
		}
	}
	top.search.popDialog(data);
}

// 编辑
function edit(e) {
	var data = {
		url : __ctx + "/users/goUsersEditPage.xhtml",
		title : "编辑",
		width : 450,
		height : 450,
		onload : function(window) {
			window.loadData({action : 'edit', entityid : e.ids});
		},
		ondestroy : function(result){
			if (result == 'ok')
				grid.reload();
		}
	}
	top.search.popDialog(data);
}

// 重置密码
function resetpwd(e) {
	top.search.confirm({content : "确定重置登录密码？", funl : function() {
		$.post(__ctx + '/users/resetPassword.xhtml', {entityids : e.ids}, function(result) {
			if (result.status) {
				top.search.info({content : '操作成功', funl : function() {
					grid.reload();
				}});
			} else {
				SearchUtils.msg(result.result);
			}
		});
	}});
}

// 查看详情
function queryDetail(e) {
	var data = {
		url : __ctx + "/users/goUsersViewPage.xhtml",
		title : "查看详情",
		width : 450,
		height : 400,
		onload : function(window) {
			window.loadData({entityid : e.ids});
		},
		ondestroy : function(result){
			if (result == 'ok')
				grid.reload();
		}
	}
	top.search.popDialog(data);
}

//查询
var queryParams = new Form('query-params');
function doSearch() {
	grid.load($.extend({isrecycle : isrecycle}, queryParams.getData()));
}